package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author dingchunlin
 * @Date 2023/8/6 21:16
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分类管理相关接口")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 分类管理分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    @ApiOperation("分类管理分页查询")
    @GetMapping("/page")
    public Result<PageResult> categoryByPage(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult result = categoryService.categoryByPage(categoryPageQueryDTO);
        return Result.success(result);
    }

    /**
     *添加分类
     * @param categoryDTO
     * @return
     */
    @PostMapping
    @ApiOperation("添加分类")
    public Result saveCategory(@RequestBody CategoryDTO categoryDTO){
        categoryService.saveCategory(categoryDTO);
        return Result.success();
    }

    /**
     * 根据分类id进行修改
     * @param categoryDTO
     * @return
     */
    @PutMapping
    @ApiOperation("根据分类id进行修改")
    public Result updateCategory(@RequestBody CategoryDTO categoryDTO){
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }

    /**
     * 根据分类id进行状态的修改
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("根据分类id进行状态的修改")
    public Result updateStatus(@PathVariable("status")Integer status,Long id){
        categoryService.updateStatus(status,id);
        return Result.success();
    }

    /**
     * 根据分类id进行删除
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("根据分类id进行删除")
    public Result deleteCategory(Long id){
        return  categoryService.deleteCategory(id);
    }

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result categoryList(Integer type){
        return Result.success(categoryService.categoryList(type));
    }
}
